package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.RoomInfo;
import com.llgz.hotelmanageapi.pojo.DO.UserInfo;
import com.llgz.hotelmanageapi.pojo.DO.UserInfo;
import com.llgz.hotelmanageapi.pojo.DO.UserInfo;
import com.llgz.hotelmanageapi.service.impl.UserInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/userInfo")
@Api(tags = "用户信息接口")
public class UserInfoController {

    @Autowired
    private UserInfoServiceImpl userInfoService;

    /**
     * @MethodName getUserInfoList
     * @Params * @param UserInfo
     * @Description 查找全部
     * @Return CommonResult
     */
    @GetMapping("/getUserInfoList")
    @ApiOperation(value = "查找", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getUserInfoList(@RequestParam String query,@RequestParam Integer pageNum,@RequestParam Integer pageCount){
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("modified_time");
        queryWrapper.like(!StringUtils.isEmpty(query),"username",query);
        IPage<UserInfo> page = userInfoService.page(new Page<>(pageNum, pageCount), queryWrapper);
        return CommonResult.successResponse(page);
    }

    @PostMapping("/addUserInfo")
    @ApiOperation(value = "添加", response = CommonResult.class, httpMethod = "POST")
    public CommonResult addRoomInfo(@RequestBody UserInfo userInfo){
        boolean save = userInfoService.save(userInfo);
        return CommonResult.successResponse(save);
    }

    @GetMapping("/getUserInfoById")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getUserInfoById(@RequestParam String id){
        UserInfo category = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("id", id));
        return CommonResult.successResponse(category);
    }
    /**
     * @MethodName updateUserInfo
     * @Params * @param UserInfo
     * @Description 更新
     * @Return CommonResult
     */
    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "更新", response = CommonResult.class, httpMethod = "POST")
    public CommonResult updateUserInfo (@RequestBody UserInfo userInfo){
        boolean b = userInfoService.updateById(userInfo);
        return CommonResult.successResponse(b);
    }
//    /**
//     * @MethodName deleteUserInfo
//     * @Params * @param UserInfo
//     * @Description 删除
//     * @Return CommonResult
//     */
//    @PostMapping("/deleteUserInfo")
//    @ApiOperation(value = "删除", response = CommonResult.class, httpMethod = "POST")
//    public CommonResult deleteUserInfo (@RequestParam String id){
//        boolean b = userInfoService.removeById(id);
//        return CommonResult.successResponse(b);
//    }
    /**
     * @MethodName deleteUserInfo
     * @Params * @param UserInfo
     * @Description 删除（多选）
     * @Return CommonResult
     */
    @PostMapping("/deleteUserInfo")
    @ApiOperation(value = "删除（多选）", response = CommonResult.class, httpMethod = "POST")
    public CommonResult deleteUserInfo (@RequestBody List<String> ids){
        boolean b = userInfoService.removeByIds(ids);
        return CommonResult.successResponse(b);
    }


}

